package dao

import (
	"go-zero-demo/user-rpc/internal/dao/entity"
	"gorm.io/gorm"
)

func CreateBatchUserRoleTx(tx *gorm.DB, dataArr []*entity.UserRoleEntity) ([]int32, error) {
	createRs := tx.Debug().Create(dataArr)
	if createRs.Error != nil {
		// rollback ...
		tx.Rollback()
		return nil, createRs.Error
	}
	var ids []int32
	for _, user := range dataArr {
		ids = append(ids, int32(user.UserRoleId))
	}
	return ids, nil
}
